package com.star.jersey.mybatisplus.base.core.contract;

import lombok.Data;

import java.io.Serializable;

/**
 * 基础查询条件
 * @author zhouhengzhe
 */
@Data
public class BaseQueryParam implements Serializable {
    private static final long serialVersionUID = -5283460708108514233L;
    /**
     * 当前页码，从1开始，默认1
     */
    protected long page = 1L;
    /**
     * 每页显示记录数, 默认10
     */
    protected long limit = 10L;
    /**
     * 排序字段 多字段用,（小写逗号）隔开 驼峰式
     */
    private String orderField;
    /**
     * 是否升序 默认降序
     */
    private boolean asc;

    public BaseQueryParam(long page, long limit) {
        if (page > 1L) {
            this.page = page;
        }

        this.limit = limit;
    }

    public long getStartIndex() {
        return (this.page - 1L) * this.limit;
    }

    public long getEndIndex() {
        return this.getStartIndex() + this.limit;
    }

    public BaseQueryParam() {
    }

    public BaseQueryParam(long page, long limit, String orderField, boolean asc) {
        this.page = page;
        this.limit = limit;
        this.orderField = orderField;
        this.asc = asc;
    }
}